package com.group9.handinhand.controller.form;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

import com.group9.handinhand.service.so.ActivityEnums.ActivityType;
import com.group9.handinhand.service.so.RequestSO;
import com.group9.handinhand.service.so.TagSO;
import com.group9.handinhand.service.so.UserSO;

public class RequestUpdateForm {
	
	RequestSO request;
	List<UserSO> moderators;
	String selectedTags;
	String endingDay;
	String endingHour;
	
	
	public RequestUpdateForm() {
		// TODO Auto-generated constructor stub
	}
	
	public RequestSO getRequest() {
		return request;
	}

	public void setRequest(RequestSO request) {
		this.request = request;
	}

	public List<UserSO> getModerators() {
		return moderators;
	}

	public void setModerators(List<UserSO> moderators) {
		this.moderators = moderators;
	}

	public String getSelectedTags() {
		return selectedTags;
	}

	public void setSelectedTags(String selectedTags) {
		this.selectedTags = selectedTags;
	}

	public String getEndingDay() {
		return endingDay;
	}

	public void setEndingDay(String endingDay) {
		this.endingDay = endingDay;
	}

	public String getEndingHour() {
		return endingHour;
	}

	public void setEndingHour(String endingHour) {
		this.endingHour = endingHour;
	}

	public List<String> getSelectedTagsAsList() {
		String[] tags = selectedTags.split(",");
		return Arrays.asList(tags);
	}
	/**
	 * A set method.
	 * Sets the selected tags as a list
	 * @param soList
	 * */
	public void setSelectedTagsFromList(List<TagSO> soList) {
		selectedTags = "";
		if(soList.size()==0)
			return;
		selectedTags += soList.get(0).getTagName();
		soList.remove(0);
		for (TagSO tag : soList) {
			selectedTags += ", " + tag.getTagName();
		}
	}
	/**
	 * A set method.
	 * Sets the experation date which includes ending day and ending hour.
	 */
	public void setEndDate() {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
		
		String endingDate = endingDay + " " + endingHour;
		
		try {
			request.setExpirationDate(dateFormat.parse(endingDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
	}
}
